#include <cstdio>
int score[1001] = {0};
main()
{
    int N;
    scanf("%d", &N);
    int group, tmp, grade;
    while(N--)
    {
        scanf("%d-%d%d", &group, &tmp, &grade);
        score[group] += grade;
    }
    int final = 0, max = -1;
    for(int e = 1; e <= 1000; ++e)
    {
        if(score[e] > max)
        {
            final = e;
            max = score[e];
        }
    }
    printf("%d %d\n", final, max);
    return 0;
}